var HOST = $('body').attr('data-host');

$(document).ready(function () {

    $('.footable').footable();
    $('.footable2').footable();


    $("body").keydown(function () {
        if (event.keyCode == "13") {//keyCode=13是回车键
            return false;
        }
    });

    $("button[name=save]").click(function () {
        var id = $(this).attr('id');
        var value = $("#ceshi" + id).val();
        var type = parseFloat($(this).attr('state'));
        var num = parseFloat('1');
        type = type + num;

        if (value == 'yes') {
            $.ajax({
                type: "POST",
                url: HOST + "/cloud.order/change_state",
                data: {"id": id, "type": type},
                async: false,
                success: function (data) {
                    if (data.info == 1) {
                        toastr.success('订单处理成功')
                    } else {
                        toastr.error('发生异常')
                    }
                }
            });
            location.reload();
        } else {
            toastr.error('如果您需要发货，请输入 yes ,否则点关闭即可');
            $('.modal').modal('hide');
        }
    });

    $("button[name=agree]").click(function () {
        var id = $(this).attr('data-id');
        var type = parseFloat($(this).attr('data-type'));
        var num = parseFloat('1');
        type = type + num;

        $.ajax({
            type: "POST",
            url: HOST + "/cloud.order/change_state",
            data: {"id": id, "type": type},
            async: false,
            success: function (data) {
                if (data.info == 1) {
                    toastr.success('订单处理成功')
                } else {
                    toastr.error('发生异常')
                }
            }
        });
        location.reload();
    });

    $("a[name=change2]").click(function () {
        var id = $(this).attr("data-id");

        $.ajax({
            type: "POST",
            url: HOST + "/cloud.order/return_goods",
            data: {
                id: id
            },
            async: false,
            success: function (data) {
                if (data) {
                    $("#express"+id).val(data['express_number']);
                    $("#time"+id).val(data['return_time']);
                    $("#reason"+id).val(data['reason']);

                } else {
                    toastr.error('发生异常')
                }

            }
        });
    });

});
